package cn.xyz.it.CommonUtil;

/**
 * @Description
 * @Author MissYu
 * @Date 2020/5/20 11:01
 * @Classname RandomUtils
 */
public class RandomUtils {

    //范围内随机数，>=num1 ,<num2
    public static int createInt(int num1, int num2) {
        int n = num1 + (int) (Math.random() * (num2 - num1));
        return n;
    }

    //范围内随机数， >=num1 ,<num2m ，*1000 线程中用
    public static int createMilliSecond(int num1, int num2) {
        return (num1 + (int) (Math.random() * (num2 - num1))) * 1000;
    }

    //返回数组中随机一个数字
    public static Integer getRandomInteger(Integer[] ints) {
        Integer intt = null;
        int v = (int) (Math.random() * ints.length);
        return intt = ints[v];
    }

    //返回数组中随机一个字符串
    public static String getRandomString(String[] doc) {
        String random = "";
        int index = (int) (Math.random() * doc.length);
        return random = doc[index];
    }

    public static void main(String[] args) {
        String[] doc = {"成功领取赠险", "安全到家", "已领取50万保障", "和家人团聚", "在家中贴春联"};
        System.out.println("随机字符串测试：   ： " + getRandomString(doc));
        Integer[] ints = {5, 6};
        System.out.println("随机数字测试：    ： " + getRandomInteger(ints));


    }
}
